﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Add.aspx.cs" Inherits="JKF.Web.Point_Log.Add" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
        <%=RegScript("~/js/jquery.1.5.js")%>
        <%=RegScript("~/js/Common.js")%>
        <%=RegScript("~/js/jquery.json.js")%>
        <%=RegScript("~/js/jquery.nhis.js")%>
        <%=RegScript("~/js/jquery.rchis.js")%>
        <%=RegScript("~/js/jquery.validate.js")%>
        <%=RegScript("~/js/DatePicker/WdatePicker.js")%>
        <%=RegStyle("~/js/suggest/jquery.suggest.css")%>
        <%=RegScript("~/js/jquery-ui-custom.min.js")%>
        <%=RegScript("~/js/check.js")%>
        <script src="../../js/Uppop/tipswindown2.js"  type="text/javascript"></script>
        
     <link href="../../App_Themes/Theme2/Include.css"   rel="stylesheet" type="text/css" />

    <script type="text/javascript" language="javascript">
        var isAdd = '<%=NoAddRedirect%>'  //没有权限跳转到提示页面
        $(function () {
            $("#BtnSave").click(function () {
                savePointLog();
            })
        });     
    </script>

    <script type="text/javascript">
        var arrLinkBtn = new Array();
        arrLinkBtn.push(new Array('clearForm()', '继续添加')); //调用函数的参数要用双引号
        arrLinkBtn.push(new Array('parent.tipsWindown.close()', '返回列表')); //调用函数的参数要用双引号


        var AppPath = "<%=AppPath %>";
        var handler = AppPath + '/do/Points/Point_Log.do';
        var scid = '<%=P("pointKey") %>';
        var customerKey = '<%=P("customerKey")%>';
        var CARD_NO = '<%=P("CARD_NO")%>';
        var NAME = '<%=P("NAME")%>';
        var MOBILE = '<%=P("MOBILE") %>';
        var GIVE_POINTS = '<%=P("GIVE_POINTS")%>';
        var CONSUME_POINTS = '<%=P("CONSUME_POINTS")%>';
        var TOTAL_POINT = '<%=P("TOTAL_POINT") %>';

        var dateCreate = '<%=DateTime.Now.ToString("yyyy-MM-dd") %>'; //如果是添加则取当前日期 如果是修改则是数据创建时间
        var ntEmpt = /^[^ ]+$/;
        var dtReg = /^\d{4}(\/|-)([1][0-2]|[1-9]|0[1-9])(\/|-)([1-2][0-9]|3[0-1]|[1-9]|0[1-9])( (0?[0-9]|1[0-9]|2[0-4])(:([0-5][0-9])){1,2})?$/;

        $(function () {
            $("#CARD_NO").val(CARD_NO);
            $("#NAME").val(NAME);
            check();

            $('#btnclose').click(function () {
                parent.tipsWindown.close();
            });
        });

        function check() {
            alxVr.push({ id: "POINT_TIME", rule: function (jd) {
                    var val = $.trim(jd.val());
                    if (!dtReg.test(val)) {
                        this.msg = "积分日期格式不正确，应(2011-1-1)"; 
                        return false;
                    } 
                    return true;
                }
             });

             alxVr.push({ id: "POINT_VALUE", rule: function (jd) {
                 var val = $.trim(jd.val());
                 if (val.length > 0) {
                     if (!isInteger(val)) {
                         this.msg = "积分值应为整数"; return false;
                     }
                 }
                 else {
                     this.msg = "积分值不能为空，请输入积分值"; return false;
                 }
                 return true;
                }
             });
            /*
             alxVr.push({
                 id: 'POINT_VALUE',
                 rule: function (jd) {
                     var v = jd.val();
                     alert(v);
                     alert("aa");
                     if (!ntEmpt.test(jd.val())) {
                         this.msg = "请录入积分值"; return false;
                     }
                     alert("bb")
                     if (v.length > 5) {
                         this.msg = "积分值不应大于5位"; return false;
                     }
                     if (!isInteger(v))
                         this.msg = "积分值应为整数"; return false;
                     return true;
                     //var reg = /^\d+$/;
                     //return reg.test(jd.val());
                 },
                 msg: '积分值应为整数',
                 isReq: false
             });*/

            alxVr.push({ id: "CODE",
                rule: function (jd) {
                    if (!ntEmpt.test(jd.val())) {
                        this.msg = "请选择积分类型"; return false;
                    } 
                    return true;
                }
            });

            alxVr.push({ id: "MEMO",
                rule: function (jd) {
                    if ($.FxNull(jd.val(), "").length > 50) {
                        this.msg = "备注在50个字符之内."; return false;
                    } return true;
                }
            });

            alxVr.push({ id: "WAY",
                rule: function (jd) {
                    if ($.FxNull(jd.val(), "").length > 50) {
                        this.msg = "积分途径应在50个字符之内."; return false;
                    } return true;
                }
            });

            $.validateBind();
        }

        function savePointLog() {
            if (!$.validateAll()) {
                if ($(".alxv-failed").size() > 0) {
                    $(document).scrollTop($(".alxv-failed").eq(0).scrollTop());
                }
                return;
            };

            var tObj = {}, objCfg = {}, pName;
            $(":text,input:checked,select").each(function () {
                pName = ($.FxNull($(this).attr("type"), "").toLowerCase() == "radio") ? $.FxNull($(this).attr("name"), "").toUpperCase() : $.FxNull($(this).attr("id"), "").toUpperCase();

                tObj[pName] = (objCfg[pName]) ? $.FxNull($(this).attr(objCfg[pName]), "") : $(this).val();
            });

            if ($.FxNull(scid, "").length > 10) {//主键
                tObj.POINT_KEY = scid;
            }
            else {
                tObj.POINT_KEY = "";
            }


            if ($.FxNull(customerKey, "").length > 10) {//主键
                tObj.CUSTOMER_KEY = customerKey;
            }
            else {
                tObj.CUSTOMER_KEY = "";
                alert("参数错误");
                return
            }

            $.post(handler, { ActionName: "EditOrInsertPoingLog", pointLogObj: $.toJSON(tObj) }, function (rslt) {
                if (rslt.MessageCode == "Ok") {//保存成功
                    updateView(); //添加或修改数据成功后更新列表页面
                    $.popResultTip('操作成功', arrLinkBtn)
                    return;
                }
                alert(rslt.Message);
            }, "json");

        }

        function updateView() {
            $("#POINT_VALUE").val();
            if ($("#CODE").val() == "01") //消费积分
                CONSUME_POINTS = parseInt(CONSUME_POINTS) + parseInt($("#POINT_VALUE").val());
            else
                GIVE_POINTS = parseInt(GIVE_POINTS) + parseInt($("#POINT_VALUE").val());

            //TOTAL_POINT = parseInt(TOTAL_POINT) + parseInt($("#POINT_VALUE").val())

            tr = $("<tr key=" + item.CUSTOMER_KEY + "></tr>");
            $('<td  width="200px"></td>').appendTo(tr).html('<input class="btn_style" value="添加积分" type="button" onclick="addPoint(' + "'" + customerKey + "','" + CARD_NO + "','" + NAME + "','" + MOBILE + "','" + GIVE_POINTS + "','" + CONSUME_POINTS + "','" + TOTAL_POINT + "'" + ')" ><input class="btn_style" value="查看积分日志" type="button"   onclick="viewPointLog(' + "'" + customerKey + "'" + ')">');

            $('<td width="150px"></td>').appendTo(tr).text(CARD_NO);
            $('<td width="150px"></td>').appendTo(tr).text(NAME);
            $('<td width="150px"></td>').appendTo(tr).text(MOBILE);      
            $('<td width="150px"></td>').appendTo(tr).text(CONSUME_POINTS);
            $('<td width="150px"></td>').appendTo(tr).text(TOTAL_POINT);
            $('<td width="150px"></td>').appendTo(tr).text(GIVE_POINTS);
            window.parent.popRetuInfo($(tr), customerKey)
        }

        function clearForm() {
            $("#POINT_VALUE").val("");
            $("#CODE").val("");
            $("#WAY").val("");
            $("#MEMO").val("");
            $('#resultTipDiv').dialog('close');  //关闭弹出提示层
        } 
    </script>
</head>
<body id="modulebody">
    <div class="pop_logging_body" style="padding:22px 70px; margin-top:0px; margin-bottom:26px; margin-right:35px; margin-left:35px ">
          <table width="100%" border="0" cellspacing="0" cellpadding="0"   class="common_table_noborde">
              <tr>
                 <td width="15%" align="right">顾客卡号</td>
                 <td width="29%">
                     <input id="CARD_NO" type="text" disabled="disabled" /></td>
                 <td width="5%">&nbsp;</td>
                 <td width="14%" align="right"><span class="fred">*</span>顾客姓名</td>
                 <td width="33%">
                     <input id="NAME" type="text" disabled="disabled" /></td>
              </tr>
               <tr>
                 <td align="right"><span class="fred">*</span>积分日期</td>
                 <td><input id="POINT_TIME" type="text"  onfocus="WdatePicker()" value="<%=DateTime.Now.ToString("yyyy-MM-dd") %>"/>
                     </td>
                 <td>&nbsp;</td>
                 <td align="right"><span class="fred">*</span>积分值</td>
                 <td>
                    <input id="POINT_VALUE" type="text" />(可为负数)
                 </td>
                
              </tr>
               <tr>
                 <td align="right"><span class="fred">*</span>积分类型</td>
                 <td>      <select id="CODE" class="common_search_select w150">
                            <option value="">请选择</option>
                            <%=PonitTypeOption%>
                        </select>
                  </td>
                   <td>&nbsp;</td>
                 <td align="right">积分途径</td>
                 <td>
                     <input id="WAY" type="text" />
                 </td>              
              </tr>
               <tr>
                 <td align="right">备注</td>
                 <td><input id="MEMO" type="text" /> </td>         
                  <td>&nbsp;</td>        
                 <td></td>
                 <td></td>                       
                           
              </tr>
          </table>
      </div>
     <div class="pop_btn">
         <input id="BtnSave" type="button" class="common_btn_save mr30 mb25" value="" />
	     <input id="btnclose" type="button" class="common_btn_remove mb25" value=" "  />
     </div>
</body>
</html>
